package com.hspjava.Homework;

import java.io.BufferedReader;

public class Homework02 {
    public static void main(String[] args) {
        try {
            check("lfm", "423434", "3223423@qq.com");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void check(String name, String key, String e_mail) {

        if (name == null || key == null || e_mail == null) {
            throw new RuntimeException("参数不能为null");
        }
        if (! (name.length() == 2 || name.length() == 3 || name.length() == 4)) {
            throw new RuntimeException("用户名长度错误");
        }

        if (!(key.length() == 6 && isDigital(key))) {
            throw new RuntimeException("密码长度错误, 或者存在非数字");
        }

        int a = e_mail.indexOf('@');
        int b = e_mail.indexOf('.');
        if (!(a > 0 && b > 0 && a < b)) {
            throw new RuntimeException("邮箱要求存在@和. 并且@在前面");
        }
        System.out.println("注册成功");
    }
    public static boolean isDigital(String str) {
        char[] p = str.toCharArray();
        for (char c : p) {
            if (!(c >= '0' && c <= '9')) {
                return false;
            }
        }
        return true;

    }
}
